<template>
  <div class="">
    <ul>
      <h1>正在进行 ==={{ num1.a }}</h1>
      <li
        v-for="(item, index) in list"
        :key="index"
        v-show="item.status == false"
      >
        <input type="checkbox" @change="change(index)" :checked="item.status" />
        <input
          type="text"
          v-model="item.title"
          v-if="index == flag"
          @blur="flag = -1"
        />
        <span @dblclick="showEdit(index)" v-else>{{ item.title }}</span>

        =====
        <span @click="remove(index)">x</span>
      </li>
    </ul>
    <ul>
      <h1>已经完成 ==={{ num1.b }}</h1>
      <li
        v-for="(item, index) in list"
        :key="index"
        v-show="item.status == true"
      >
        <input type="checkbox" @change="change(index)" :checked="item.status" />
        <span>{{ item.title }}</span>
        =====
        <span @click="remove(index)">x</span>
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  props: ["list"],
  //接收 父组件传来的list数据
  data() {
    return {
      flag: -1,
      //保存双击修改的下标
    };
  },
  mounted() {},
  methods: {
    change(index) {
      this.$emit("change", index);
    },
    //调用父组件的change方法 实现状态切换
    remove(index) {
      this.$emit("remove", index);
    },
    //调用父组件的删除方法
    showEdit(index) {
      this.flag = index;
    },
    //双击修改的时候把下标保存下来
  },
  components: {},
  computed: {
    num1() {
      let arr = this.list.filter((item) => {
        return item.status == false;
      });
      let arr1 = this.list.filter((item) => {
        return item.status == true;
      });
      // return [arr.length, arr1.length];
      return { a: arr.length, b: arr1.length };
    },
    //计算已完成未完成的数量的
    // num2() {
    //   let arr = this.list.filter((item) => {
    //     return item.status == true;
    //   });
    //   return arr.length;
    // },
  },
};
</script>

<style lang="scss"></style>
